<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class TestAction extends Action {

    /**
     * 加载首页主推荐部分的品牌
     */
    public function index() {
//        $model = new Model();
//        $headTopList = $model->table('gw_brand b, gw_market_url m')
//                ->where('b.positionFlag="0" and b.id=m.brandId')
//                ->field('b.*,m.url,m.marketId')
//                ->select();
        $headTop = D('HeadTopView');
        $where['b.positionFlag'] = '0';
        $headTopList = $headTop->where($where)->order('id')->select();
        
        echo $headTop->getlastsql();

        $headTopMarketList = array();
        for ($i = 0; $i < count($headTopList); $i++) {
            $headTopMarketList[$headTopList[$i]['id']][] = $headTopList[$i];
        }
        var_dump($headTopMarketList);
        //var_dump($headTopList);

        $this->display();
    }

    /**
     * test 数组
     */
    public function index_one() {
        $ages = array("Peter" => 11, "Quagmire" => 22, "Joe" => 33);
        for ($i = 0; $i < 3; $i++) {
            $ages[$i]['a'] = array(1, 2, 3);
        }
        var_dump($ages);
    }

    /**
     * 加载分类及其下面的品牌
     */
    public function index_two() {
        $gw_category = M('Gw_category');
        // $categoryList = $gw_category->select();

        $aArray = array();
        $bArray = array();
        $aList = $gw_category->where('level=1')->order('id')->select();
        $bList = $gw_category->where('level=2')->order('id')->select();
        $categoryBrand = D('CategoryBrandView');
        $where['b.positionFlag'] = '1';
        $cList = $categoryBrand->where($where)->order('categoryId')->select();

        for ($j = 0; $j < count($bList); $j++) {
            for ($k = 0; $k < count($cList); $k++) {
                if ($cList[$k]['categoryId'] == $bList[$j]['id']) {
                    $bArray[$bList[$j]['name']][] = $cList[$k];
                }
            }
        }


        for ($i = 0; $i < count($aList); $i++) {
            for ($j = 0; $j < count($bList); $j++) {
                if ($bList[$j]['parentId'] == $aList[$i]['id']) {
                    $aArray[$aList[$i]['name']][] = $bList[$j];
                }
            }
        }

        //var_dump($aArray);
        var_dump($bArray);
        exit;
        $this->assign('aArray', $aArray);
        $this->assign('bArray', $bArray);
        $this->display();
    }

    /**
     * 加载子类下面的品牌
     */
    public function index_three() {
        $categoryId = $this->_get('categoryId');
        $categoryBrand = D('CategoryBrandView');
        $where['bc.categoryId'] = $categoryId;
        $cList = $categoryBrand->where($where)->select();
        $count = $cList->count();
        import('ORG.Util.Page'); // 导入分页类        
        $Page = new Page($count, 10); // 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show(); // 分页显示输出
        $this->assign('cList', $cList);
        $this->assign('page', $show); // 赋值分页输出
        $this->assign('count', $count);
        $this->display();
    }

}

?>
